package com.dong.adapterMode.service;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @author DongJiaQi
 * @create 2022/12/27 9:45
 * @Description: MQ消息体适配类
 */
public class MQAdapter {

    public static RebateInfo filter(String strJson, Map<String, String>link) throws NoSuchMethodException, InvocationTargetException,
            IllegalAccessException {
        return filter(JSON.parseObject(strJson, Map.class), link);
    }
    public static RebateInfo filter(Map obj, Map<String, String> link)
            throws NoSuchMethodException, InvocationTargetException,
            IllegalAccessException {
        RebateInfo rebateInfo = new RebateInfo();
        for (String key : link.keySet()) {
            Object o = obj.get(link.get(key));
            RebateInfo.class.getMethod("set"+ StrUtil.upperFirst(key),String.class).invoke(rebateInfo,o.toString());
        }
        return rebateInfo;
    }
}
